﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GKQC.Common
{
    /// <summary>
    /// 材料料號解析
    /// </summary>
    public class MaterialCode
    {
        /// <summary>
        /// 已裁切正箔料號位數21
        /// </summary>
        public readonly static int CuttedFoilpCodeCount = 21;
        /// <summary>
        /// 導針料號位數14
        /// </summary>
        public readonly static int LeadWireCodeCount = 13;
        /// <summary>
        /// 膠蓋料號位數12
        /// </summary>
        public readonly static int RubberCodeCount = 12;
        /// <summary>
        /// 铝壳料號位數8
        /// </summary>
        public readonly static int AlCaseCodeCount = 8;

        /// <summary>
        /// 铝壳前缀C
        /// </summary>
        public static readonly string AlCasePrefix = "C";
        /// <summary>
        /// 正箔前缀F
        /// </summary>
        public static readonly string FoilpPrefix = "F";
        /// <summary>
        /// 负箔前缀FB
        /// </summary>
        public static readonly string FoilnPrefix = "FB";
        /// <summary>
        /// 电解纸前缀P
        /// </summary>
        public static readonly string EpsPrefix = "P";
        /// <summary>
        /// 导针前缀D
        /// </summary>
        public static readonly string LeadWirePrefix = "D";
        /// <summary>
        /// 导箔条前缀DB
        /// </summary>
        public static readonly string LeadWire2Prefix = "DB";
        /// <summary>
        /// 胶盖前缀B
        /// </summary>
        public static readonly string RubberPrefix = "B";
        /// <summary>
        /// 上盖前缀E
        /// </summary>
        public static readonly string UpRubberPrefix = "E";
        /// <summary>
        /// 垫片前缀G
        /// </summary>
        public static readonly string PadPrefix = "G";
        /// <summary>
        /// 铝华司前缀Z
        /// </summary>
        public static readonly string AlPadPrefix = "Z";
        /// <summary>
        /// 电解液前缀W
        /// </summary>
        public static readonly string PastePrefix = "W";
        /// <summary>
        /// 胶管前缀Y
        /// </summary>
        public static readonly string HosePrefix = "Y";
        /// <summary>
        /// 卡箍前缀K
        /// </summary>
        public static readonly string HoopsPrefix = "K";
        /// <summary>
        /// 载带前缀V
        /// </summary>
        public static readonly string TapePrefix = "V";

        static readonly string douhao = ",";
        static readonly string kongge = " ";
        static readonly char douhaoChar = ',';
        static readonly char konggeChar = ' ';
        static readonly string V = "V";
        static readonly string P = "P";
        static readonly string Z = "Z";

        public static bool OverExpriteDate(string pn,string billtype
            , DateTime incomeDate, DateTime? prodate)
        {
            int MonthsElapsed = 0;
            int ExpriteMonth = 0;

            if (string.IsNullOrWhiteSpace(pn) && string.IsNullOrWhiteSpace(billtype))
            {
                ExpriteMonth = 24;
                //if (MonthsElapsed>12)
                //{
                //    return true;
                //}
                //else
                //    return false;
            }
            
            if (!string.IsNullOrWhiteSpace(pn))
            {
                if (pn.StartsWith(HosePrefix))
                {
                    if(pn.Length>=14)
                    {
                        if (MonthsElapsed > 6)return true;
                        else return false;
                    }
                    else
                    {
                        if (MonthsElapsed > 12)return true;
                        else return false;
                    }
                }
                else if(pn.StartsWith(AlPadPrefix)
                    || pn.StartsWith(EpsPrefix)
                    || pn.StartsWith(AlCasePrefix)
                    || pn.StartsWith(RubberPrefix))
                {
                    ExpriteMonth = 24;
                    //if (MonthsElapsed > 24) return true;
                    //else return false;
                }
                else if (pn.StartsWith(FoilpPrefix) ||
                    pn.StartsWith(FoilnPrefix)
                    || pn.StartsWith(UpRubberPrefix)
                    || pn.StartsWith(PadPrefix)
                    || pn.StartsWith(TapePrefix)
                    || pn.StartsWith(LeadWirePrefix)
                    || pn.StartsWith(UpRubberPrefix)
                    || pn.StartsWith(UpRubberPrefix)
                    )
                {
                    ExpriteMonth = 12;
                    //if (MonthsElapsed > 12) return true;
                    //else return false;
                }
            }

            if (!string.IsNullOrWhiteSpace(billtype) && ExpriteMonth==0)
            {
                if (billtype == "062" || billtype == "115" || billtype == "115")
                {
                    ExpriteMonth = 6;
                    //if (MonthsElapsed > 6)
                    //    return true;
                }
                else if (billtype == "800")
                {
                    ExpriteMonth = 24;
                    //if (MonthsElapsed > 24)
                    //    return true;
                }
                else if (billtype == "802" || billtype == "803" || billtype == "805")
                {
                    ExpriteMonth = 12;
                    //if (MonthsElapsed > 12)
                    //    return true;
                }
                else
                {
                    ExpriteMonth = 12;
                    //if (MonthsElapsed > 12) return true;
                    //else return false;
                }
            }

            if (ExpriteMonth == 0) ExpriteMonth = 24;

            if (prodate.HasValue)
            {
                DateTime start = prodate.Value.AddMonths(ExpriteMonth);
                int compNum = DateTime.Compare(start, incomeDate);
                return compNum <= 0;
            }
            //MonthsElapsed = ((incomeDate.AddDays(1).Year - prodate.Value.AddDays(1).Year) * 12) +
            //    (incomeDate.AddDays(1).Month - prodate.Value.AddDays(1).Month) -
            //    (incomeDate.AddDays(1).Day < prodate.Value.AddDays(1).Day ? 1 : 0);

            return false;
        }

        /// <summary>
        /// 垫片直径D
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static double GetPadD(string pn)
        {
            double D = 0;

            if (!string.IsNullOrWhiteSpace(pn))
            {
                if (pn.StartsWith(PadPrefix) && pn.Length >= 4)
                {
                    string s = pn.Substring(2, 2);
                    D = ProductCode.GetDbyCode(s);
                }
            }

            return D;
        }

        /// <summary>
        /// 垫片耐温后直径误差
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static double GetPadDDMax(string pn)
        {
            double dd = 0;
            double D = GetPadD(pn);

            if (D >= 13 && D <= 18)
                dd = 1.2;
            else if (D >= 20 && D <= 25)
                dd = 1.5;
            else if (D >= 30 && D <= 42)
                dd =2;

            return dd;
        }


        //GetRubberType
        /// <summary>
        /// 胶盖标准类型：T普通 P固态 Vcvhip  W防爆孔  N 半月
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static string GetRubberType(string pn)
        {
            string s = string.Empty;

            if (!string.IsNullOrWhiteSpace(pn))
            {
                if (pn.StartsWith(RubberPrefix) && pn.Length >= RubberCodeCount)
                {
                    if (pn.Length > 12)
                    {
                        string ss = pn.Substring(11, pn.Length - RubberCodeCount + 1);
                        if (ss.Contains(V))
                            return V;
                        else if (ss.Contains(P))
                            return P;
                    }

                    string shape = GetRubberShape(pn);
                    if (shape == "V")
                        return "W";
                    else if(shape == "N")
                        return "N";
                }
            }

            return s;
        }

        /// <summary>
        /// 胶盖形状（料号第九位）：P平面  T常规凸面  E凸面T型  N半月和扇形  V平面带防爆孔
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static string GetRubberShape(string pn)
        {
            string s = string.Empty;

            if(!string.IsNullOrWhiteSpace(pn))
            {
                if(pn.StartsWith(RubberPrefix) && pn.Length >= RubberCodeCount)
                {
                    s = pn.Substring(8, 1);
                }
            }

            return s;
        }

        /// <summary>
        /// 胶盖厚度
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static double GetRubberL(string pn)
        {
            double  L=0;

            if (!string.IsNullOrWhiteSpace(pn))
            {
                if (pn.StartsWith(RubberPrefix) && pn.Length >= RubberCodeCount)
                {
                    string s = pn.Substring(1, 2);
                    double.TryParse(s, out L);
                }
            }

            return L;
        }

        /// <summary>
        /// 胶盖直径D
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static double GetRubberD(string pn)
        {
            double L = 0;

            if (!string.IsNullOrWhiteSpace(pn))
            {
                if (pn.StartsWith(RubberPrefix) && pn.Length >= RubberCodeCount)
                {
                    string s = pn.Substring(3, 1);
                    L = ProductCode.GetDbyCode(s);
                }
            }

            return L;
        }

        //static readonly string R = "R";
        /// <summary>
        /// 胶盖孔距P
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static double GetRubberP(string pn)
        {
            double L = 0;

            if (!string.IsNullOrWhiteSpace(pn))
            {
                if (pn.StartsWith(RubberPrefix) && pn.Length >= RubberCodeCount)
                {
                    string s = pn.Substring(4, 4);
                    double.TryParse(s.Replace(R,dot),out L);
                }
            }

            return L;
        }

        /// <summary>
        /// 胶盖孔径G
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static double GetRubberG(string pn)
        {
            double L = 0;

            if (!string.IsNullOrWhiteSpace(pn))
            {
                if (pn.StartsWith(RubberPrefix) && pn.Length >= RubberCodeCount)
                {
                    string s = pn.Substring(9, 2);
                    double.TryParse(s, out L);
                    L = Math.Round(L / 10d, 1);
                }
            }

            return L;
        }

        /// <summary>
        /// 胶盖1:材質(1=EPT、3=IIR/PO(IIR100%)、4=IIR/RE、5=耐冷熱衝擊EPT、6=IIR/RE,硬度為80±4Å)
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static string GetRubberMeterial(string pn)
        {
            string s = string.Empty;

            if (!string.IsNullOrWhiteSpace(pn))
            {
                if (pn.StartsWith(RubberPrefix) && pn.Length >= RubberCodeCount)
                {
                    s = pn.Substring(11, 1);
                }
            }

            return s;
        }


        /// <summary>
        /// 胶盖硬度
        /// 1 EPT材質: 4Φ~25Φ H=79±4A°
        /// 5 EPT（耐冷热冲击） 材质 H = 80±4A°
        /// 3 IIR材質:  H=80±4A° .      
        /// 4 RE加硫材質:H=82±4A° .
        /// 6 V-Chip、固态(RE)材质:89±4A°
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static double GetRubberA(string pn)
        {
            double s = 0;

            if (!string.IsNullOrWhiteSpace(pn))
            {
                if (pn.StartsWith(RubberPrefix) && pn.Length >= RubberCodeCount)
                {
                    string ss = pn.Substring(11, 1);
                    if (ss == "1") s = 79;
                    else if (ss == "3") s = 80;
                    else if (ss == "4") s = 82;
                    else if (ss == "5") s = 80;
                    else if (ss == "6") s = 89;
                }
            }

            return s;
        }

        /// <summary>
        /// 胶盖绝缘阻抗 MΩ
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static double GetRubberIR(string pn)
        {
            double s = 0;

            if (!string.IsNullOrWhiteSpace(pn))
            {
                if (pn.StartsWith(RubberPrefix) && pn.Length >= RubberCodeCount)
                {
                    string ss = pn.Substring(11, 1);
                    if (ss == "6") s = 100;
                    else s = 50000;
                }
            }

            return s;
        }

        /// <summary>
        /// 箔片离散率标准
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static double GetFoilLS(string pn)
        {
            double ls = 10;

            if (!string.IsNullOrWhiteSpace(pn) && pn.EndsWith("A"))
                ls = 7;

            return ls;
        }

        /// <summary>
        /// 箔片水合变化率标准
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static double GetFoilShuiheRate(string pn)
        {
            double ls = 7;

            if (!string.IsNullOrWhiteSpace(pn) 
                && (pn.EndsWith("A") || pn.StartsWith("FB"))
                )
                ls = 5;

            return ls;
        }


        /// <summary>
        /// 导针类型
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static string GetLeadWireType(string pn)
        {
            if (!pn.StartsWith(LeadWirePrefix)) return string.Empty;
            if (pn.Length < LeadWireCodeCount) return string.Empty;

            if (pn.Length >= 14 
                && (pn.Substring(13, pn.Length -13).Contains(V))
                )
                return V;
            else if (pn.Length > 14 
                && (pn.Substring(13, pn.Length - 13).Contains(P))
                )
                return P;
            else return Z;
        }

        /// <summary>
        /// 铝壳类型
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static string GetAlCaseType(string pn)
        {
            if (!pn.StartsWith(AlCasePrefix)) return string.Empty;
            if (pn.Length < AlCaseCodeCount) return string.Empty;

            if (pn.Length > AlCaseCodeCount && pn.Substring(AlCaseCodeCount, 1) == V)
                return V;
            else if(pn.Length > AlCaseCodeCount && pn.Substring(AlCaseCodeCount, 1) == P)
                return P;
            else return pn.Substring(6, 2);
        }

        /// <summary>
        /// 品名前面一截做物料名称
        /// </summary>
        /// <param name="pnName"></param>
        /// <returns></returns>
        public static string GetNameByPnName(string pnName)
        {
            string name = string.Empty;
            if (string.IsNullOrWhiteSpace(pnName) || pnName.Length < 10)
                return pnName;

            if (pnName.Contains(douhao))
                return pnName.Split(douhaoChar)[0];
            else if (pnName.Contains(konggeChar))
                return pnName.Split(konggeChar)[0];

            return pnName;
        }

        /// <summary>
        /// 品名前面一截做物料名称
        /// </summary>
        /// <param name="spec"></param>
        /// <returns></returns>
        public static string GetFirstPartSpec(string spec)
        {
            string name = string.Empty;
            if (string.IsNullOrWhiteSpace(spec) || spec.Length < 10)
                return spec;

            if (spec.Contains(douhao))
                return spec.Split(douhaoChar)[0];
            else if (spec.Contains(konggeChar))
                return spec.Split(konggeChar)[0];

            return spec;
        }

        /// <summary>
        /// 通过料号获取胶管水煮后长度收缩率
        /// </summary>
        /// <param name="pn"></param>
        /// <param name="specValue">规格</param>
        /// <param name="tolerance">公差</param>
        /// <returns></returns>
        public static double GetL5L6_Hose(string pn, out double specValue ,out double tolerance
            , out double toleranceN)
        {
            specValue = 0;
            tolerance = 0;
            toleranceN = 0;

            if (string.IsNullOrWhiteSpace(pn) || pn.Length < 2 || !pn.StartsWith(HosePrefix)) return 0;

            string dcode = GetDCode_Hose(pn);
            specValue = ProductCode.GetDbyCode(dcode);

            if(specValue >=4 && specValue <= 40)
            {
                specValue = 8;
                tolerance = 5;
                toleranceN = 5;
            }
            else if (specValue >= 50 && specValue <= 100)
            {
                specValue = 15;
                tolerance = 5;
                toleranceN = 5;
            }

            return specValue;
        }

        /// <summary>
        /// 通过料号获取胶管水煮后长度收缩率
        /// </summary>
        /// <param name="pn"></param>
        /// <param name="specValue">规格</param>
        /// <param name="tolerance">公差</param>
        /// <returns></returns>
        public static string GetL5L6_HoseDesc(string pn, double specValue, double tolerance, double toleranceN)
        {
            if(specValue ==0 && tolerance==0)
                GetL5L6_Hose(pn, out specValue, out tolerance,out toleranceN);

            if (specValue > 0 && tolerance > 0 && tolerance == toleranceN)
                return specValue + "±" + tolerance.ToString();
            else if (specValue > 0 && tolerance > 0 && tolerance != toleranceN)
                return specValue + "+" + tolerance.ToString() +
                Environment.NewLine + "-" + toleranceN.ToString();
            else if (specValue == 0 && tolerance > 0 && toleranceN > 0)
                return (-toleranceN).ToString() + "~" + tolerance.ToString();
            else
                return string.Empty;
        }

        /// <summary>
        /// 通过料号获取胶管水煮后折径收缩率
        /// </summary>
        /// <param name="pn"></param>
        /// <param name="specValue">规格</param>
        /// <param name="tolerance">公差</param>
        /// <returns></returns>
        public static double GetL7L8_Hose(string pn, out double specValue
            , out double tolerance, out double toleranceN)
        {
            specValue = 0;
            tolerance = toleranceN = 0;

            if (string.IsNullOrWhiteSpace(pn) || pn.Length < 2 || !pn.StartsWith(HosePrefix)) 
                return 0;

            string dcode = GetDCode_Hose(pn);
            specValue = ProductCode.GetDbyCode(dcode);

            if (pn == "YD-T410C2")//20220719
            {
                specValue = 50;
                tolerance = 3;
                toleranceN = 2;
            }
            else if (specValue >= 4 && specValue <= 12.5)
            {
                specValue = 49;
                tolerance = toleranceN = 3;
            }
            else if (specValue==50)
            {
                specValue = 50;
                tolerance = toleranceN = 3;
            }
            else if (specValue >= 13 && specValue <= 45)
            {
                specValue = 45;
                tolerance = toleranceN = 3;
            }
            else if (specValue >= 51 && specValue <= 100)
            {
                specValue = 40;
                tolerance = toleranceN = 5;
            }

            return specValue;
        }

        /// <summary>
        /// 通过料号获取胶管水煮后长度收缩率
        /// </summary>
        /// <param name="pn"></param>
        /// <param name="specValue">规格</param>
        /// <param name="tolerance">公差</param>
        /// <returns></returns>
        public static string GetL7L8_HoseDesc(string pn, double specValue, double tolerance, double toleranceN)
        {
            //double specValue = 0;
            //double tolerance = 0;
            //double toleranceN = 0;

            if(specValue ==0 && tolerance==0)
                GetL7L8_Hose(pn, out specValue, out tolerance, out toleranceN);
            if (specValue > 0 && tolerance > 0 && tolerance == toleranceN)
                return specValue + "±" + tolerance.ToString();
            else if (specValue > 0 && tolerance > 0 && tolerance != toleranceN)
                return specValue + "+" + tolerance.ToString() +
                Environment.NewLine + "-" + toleranceN.ToString();
            else if (specValue == 0 && tolerance > 0 && toleranceN > 0)
                return toleranceN.ToString() + "-" + tolerance.ToString();
            else
                return string.Empty;
        }

        /// <summary>
        /// 通过料号获取胶管直径
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static double GetD_Hose(string pn)
        {
            double d = 0;

            if (string.IsNullOrWhiteSpace(pn) || pn.Length < 2 || !pn.StartsWith(HosePrefix)) return 0;

            d = ProductCode.GetDbyCode(GetDCode_Hose(pn));

            return d;
        }
         public static string GetDCode_Hose(string pn)
        {
            string c = string.Empty;

            if (string.IsNullOrWhiteSpace(pn) || pn.Length < 2 || !pn.StartsWith(HosePrefix)) 
                return c;

            if (pn.Length >= 15)
                c = pn.Substring(10, 1);
            else
                c = pn.Substring(1, 1);

            return c;
        }

        /// <summary>
        /// 通过料号获取铝壳直径
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static double GetD_AlCase(string pn)
        {
            double d = 0;

            if (string.IsNullOrWhiteSpace(pn)|| pn.Length <2 || !pn.StartsWith(AlCasePrefix)) return 0;

            d = ProductCode.GetDbyCode(pn.Substring(1, 1));

            return d;
        }


        static readonly string B = "B";
        static readonly string R = "R";
        static readonly string dot = ".";
        /// <summary>
        /// 通过料号获取铝壳高度
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static double GetL_AlCase(string pn)
        {
            double d = 0;

            if (string.IsNullOrWhiteSpace(pn) || pn.Length < 6 || !pn.StartsWith("C")) return 0;

            string code = pn.Substring(2, 4);
            if(code.Contains(B))
            {
                double.TryParse(code.Replace(B, string.Empty).Replace(R, dot), out d);
                d += 0.5;
            }
            else
            {
                double.TryParse(code.Replace(R, dot), out d);
            }

            return d;
        }

        /// <summary>
        /// 通过料号获取导针B部直径
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static double GetB_LeadWire(string pn)
        {
            double d = 0;

            if (string.IsNullOrWhiteSpace(pn) || pn.Length < 13 || !pn.StartsWith(LeadWirePrefix)) return 0;

            string code = pn.Substring(1, 2);

            double.TryParse(code, out d);
            d = Math.Round(d / 10, 1);

            return d;
        }

        /// <summary>
        /// 高压化成
        /// </summary>
        static readonly List<string> HighVoltage = new List<string>() {"F6","C3" };
        /// <summary>
        /// 通过料号获取导针化成电压
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static double GetVoltage_LeadWire(string pn)
        {
            double d = 0;

            if (string.IsNullOrWhiteSpace(pn) || pn.Length < 13 || !pn.StartsWith(LeadWirePrefix)) return 0;

            string code = pn.Substring(9, 2);

            if (code == "F5")
                d= 200;
            else if (code == "F6")
                d = 450;
            else if (code == "C1" || code == "C2")
                d = 160;
            else if (code == "C3")
                d = 400;

            return d;
        }

        /// <summary>
        /// 通过料号获取导针化成电流
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static double GetCurrent_LeadWire(string pn)
        {
            double d = 0.5;

            if (string.IsNullOrWhiteSpace(pn) || pn.Length < 13 || !pn.StartsWith(LeadWirePrefix)) return 0;

            string code = pn.Substring(9, 2);

            if (HighVoltage.Contains(code))
                d = 1;

            return d;
        }

        /// <summary>
        /// 通过料号获取导针漏电流测试电压
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static double GetLcVoltage_LeadWire(string pn)
        {
            double d = 80;

            var b = GetB_LeadWire(pn);
            if (b > 1) d = 100;

            return d;
        }

        /// <summary>
        /// 獲取已裁切正箔料號中的裁切寬度
        /// </summary>
        /// <param name="mn"></param>
        /// <returns></returns>
        public static double GetCuttedFoilpWidth(string mn)
        {
            double d = 0;

            if (string.IsNullOrWhiteSpace(mn) || mn.Length != CuttedFoilpCodeCount || !mn.StartsWith("F"))
                return d;

            string s = mn.Substring(mn.Length - 4, 4);
            s = s.Replace("R", ".");
            double.TryParse(s, out d);

            return d;
        }

        /// <summary>
        /// 獲取已裁切負箔料號中的裁切寬度
        /// </summary>
        /// <param name="mn"></param>
        /// <returns></returns>
        public static double GetCuttedFoilnWidth(string mn)
        {
            double d = 0;

            if (string.IsNullOrWhiteSpace(mn) || !mn.StartsWith("FB") || mn.StartsWith("FB-") || mn.Length<6)
                return d;

            string s = mn.Substring(3,4);
            s = s.Replace("R", ".");
            double.TryParse(s, out d);

            return d;
        }

        /// <summary>
        /// 獲取已裁切電解紙料號中的裁切寬度
        /// </summary>
        /// <param name="mn"></param>
        /// <returns></returns>
        public static double GetCuttedEpsWidth(string mn)
        {
            double d = 0;

            if (string.IsNullOrWhiteSpace(mn) || !mn.StartsWith("P") || mn.StartsWith("P-") || mn.Length < 6)
                return d;

            string s = mn.Substring(1, 4);
            s = s.Replace("R", ".");
            double.TryParse(s, out d);

            return d;
        }

        /// <summary>
        /// 導針直徑
        /// </summary>
        /// <param name="mn"></param>
        /// <returns></returns>
        public static double GetLeadWireDiam(string mn)
        {
            double d = 0;

            if (string.IsNullOrWhiteSpace(mn) || mn.Length < LeadWireCodeCount || !mn.StartsWith("D"))
                return d;

            string s = mn.Substring(1, 2);
            switch(s)
            {
                case "10":
                    d = 1.0;
                    break;
                case "12":
                    d = 1.2;
                    break;
                case "15":
                    d = 1.5;
                    break;
                case "20":
                    d = 2.0;
                    break;
                default:
                    break;
            }

            return d;
        }

        /// <summary>
        /// 膠蓋厚度(19=1.9mm、26=2.6mm、40=4.0mm、50=5.0mm、55=5.5mm、60=6.0mm)
        /// </summary>
        /// <param name="mn"></param>
        /// <returns></returns>
        public static double GetRubberThickness(string mn)
        {
            double d = 0;

            if (string.IsNullOrWhiteSpace(mn) || mn.Length != RubberCodeCount || !mn.StartsWith("B"))
                return d;

            string s = mn.Substring(1, 2);
            switch (s)
            {
                case "19":
                    d = 1.9;
                    break;
                case "26":
                    d = 2.6;
                    break;
                case "40":
                    d = 4.0;
                    break;
                case "55":
                    d = 5.5;
                    break;
                case "60":
                    d = 6.0;
                    break;
                default:
                    break;
            }

            return d;
        }
    }
}
